<%@page import="java.net.URLEncoder"%>
<%@page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>准备下载</title>
<%
	int id=Integer.parseInt(request.getParameter("id"));
	Class.forName("com.mysql.jdbc.Driver");
	Connection con=DriverManager.getConnection((String) application.getAttribute("dburl"),(String) application.getAttribute("username"),(String) application.getAttribute("password"));
	Statement s=con.createStatement();
	String sqls1="SELECT file,name FROM data WHERE id="+id;
	ResultSet rs=s.executeQuery(sqls1);
	rs.last();
	if(rs.getRow()==0){
		out.println("内部错误-0007：无法找到id对应的file，请联系QQ2276768747解决问题！");
		return ;
	}
	rs.beforeFirst();
	rs.next();
	String filename=rs.getString(1);
	String name=rs.getString(2);
	response.setContentType("application/x-download");
	String filedownload = "/data/"+filename;
	String filedisplay = filename;
      	filedisplay = URLEncoder.encode(filedisplay,"UTF-8");
      	response.addHeader("Content-Disposition","attachment;filename=" + filedisplay);
      	try{
            RequestDispatcher dis = application.getRequestDispatcher(filedownload);
            if(dis!= null)
	    {
	        dis.forward(request,response);
	    }
            response.flushBuffer();
	}catch(Exception e){
	    e.printStackTrace();
	}finally{
	    out.println("id="+id);
	    out.println("name="+name);
	}
%>
</head>
<body>
您的下载即将开始，下载开始后可直接关闭本界面！
</body>
</html>